package com.gitee.magic.framework.head.converter;

import com.gitee.magic.core.converter.AbstractConverterEditor;
import com.gitee.magic.core.utils.codec.Base64;

/**
 * @author start
 */
public class Base64ConverterEditor extends AbstractConverterEditor<String> {

	public Base64ConverterEditor(Class<?> prototype) {
		super(prototype);
	}

	@Override
	public void restore(Object value) {
		if (value != null) {

			setValue(new String(Base64.decode(String.valueOf(value))));
		}
	}

	@Override
	public String converter() {
		if (getValue() == null) {
			return null;
		}
		return Base64.encode(String.valueOf(getValue()).getBytes());
	}

}
